import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import TabbarHome from '@/views/TabbarPages/TabbarHome.vue'
import store, { StateAll } from '@/store/index'


const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Tabbar',
    component: TabbarHome,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/TabbarPages/Home/index.vue')
      },
      {
        path: 'capital',
        name: 'Capital',
        component: () => import('@/views/TabbarPages/Capital/routerIndex.vue'),
        children: [
          {
            path: '',
            name: 'Capital2',
            component: () => import('@/views/TabbarPages/Capital/index.vue'),
          },
          {
            path: 'recharge',
            name: 'Recharge',
            component: () => import('@/views/TabbarPages/Capital/recharge.vue'),
          },
          {
            path: 'withdrawal',
            name: 'Withdrawal',
            component: () => import('@/views/TabbarPages/Capital/withdrawal.vue'),
          },
          {
            path: 'confirmWithdrawal',
            name: 'ConfirmWithdrawal',
            component: () => import('@/views/TabbarPages/Capital/confirmWithdrawal.vue'),
          },
          {
            path: 'personalCenter',
            name: 'personalCenter',
            component: () => import('@/views/TabbarPages/Capital/personalCenter.vue'),
          },
        ]
      },
      {
        path: 'task',
        name: 'Task',
        component: () => import('@/views/TabbarPages/Task/routerIndex.vue'),
        children: [
          {
            path: '',
            name: 'Task2',
            component: () => import('@/views/TabbarPages/Task/index.vue'),
          },
        ]
      },
    ]
  },
  {
    path: '/webview',
    name: 'Webview',
    component: () => import('@/views/TabbarPages/Home/webView.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})



router.beforeEach((to, from, next) => {
  // const token = (store.state as StateAll).users.token
  const infos = (store.state as StateAll).users.infos
  if (infos.token) {
    store.dispatch('users/getUserInfo')
  }
  next()
})

export default router
